package com.njwb.day05;

public class People {
    String name;
    boolean sex;
    People spouse;

    public People(String name,boolean sex){
        this.name=name;
        this.sex=sex;
    }

    public void marry(People spouse){
        if(this==spouse){
            System.out.println("自己不能跟自己结婚");
            return;
        }
        if(this.sex==spouse.sex){
            System.out.println("同性不能结婚");
            return;
        }
        if(this.spouse!=null||spouse.spouse!=null){
            System.out.println("结过婚的不能再结婚");
            return;
        }

        //当前对象的配偶是传入的对象
        //传入对象的配偶是当前对象
        this.spouse=spouse;
        spouse.spouse=this;
        System.out.println("百年好合！");
    }
}
